Scroll Progress Bar

Library Functions

It is a pre-written program that comes with turbo 'C' package. Collection of related library functions is supplied in the form of header file. To use any library function, the respective header file must be # included.

printf(): (output)

This library function is available in stdio.h header file. It is used to display a message, constant, value of a variable and result of an expression.

Suytax 1: printf("message");
Example:-

    printf ("Hello ");
    printf ("welcome");
Suytax 2: printf ('format specifier", var1 [,var2,. ..]);
Example:-

    printf ("%d", a);
    printf ("%f", a);
    printf ("%c", a);
Scanf():- input

This library function is available in stdio.h header File. It is used to accept data variables at runtime.

Syntax: scanf ("format Specifier", & var1 [,var2, … ]);
Example:-

    scanf ("%d", &a) ;
    scanf ("%f", &b) ;
    scanf ("%c", &p) ;
    scanf ("%d%f %c", &a&b&p) ;

The following program helps to accept principle, number of years and rate of interest and calculate the simple interest:

Program:

// Header file
#include <stdio.h>

// Main function
int main() 
{
    // Declare the float variables
    float principal, years, rate_of_interest,simple_interest;

    // Accept the input from the user
    printf("Enter the principal amount: ");
    scanf("%f", &principal);

    printf("Enter the number of years: ");
    scanf("%f", &years);

    printf("Enter the rate of interest: ");
    scanf("%f", &rate_of_interest);

    // Calcuare simple intrest
    simple_interest = (principal * years * rate_of_interest) / 100;
    
    // Display simple interest
    printf("Simple Interest: %.2f\n", simple_interest);

    return 0;
}
Sample output:

Enter the principal amount: 25000
Enter the number of years: 5
Enter the rate of interest: 2
Simple Interest: 2500.00

What is the C library function for finding the length of a string?


strlen

Which library function is used to allocate memory dynamically in C?


malloc

What is the C library function for reading characters from a file?


fgetc

Which library function is used to open a file in C?


fopen

What C library function is used for integer division with remainder?


div